import CommunityModule from '../../../models/3.0/community'
import dateDiff from '../../../util/dateDiff'
Page({
  /**
   * Page initial data
   */
  data: {
    active: 0,
    showLoading:false,
    id:'',
    name:'',
    attentionNumber:'',
    dynamicNumber:'',
    attentionState:'',
    list:'',
    followed:'',
    newlist:'',
    newfollowed:''
  },
  Moments(type){
    console.log('type',type);
    CommunityModule.Moments({ 
      condition:1 ,
      count:10,
      id:+this.data.id,
      userId:wx.getStorageSync('userInfo').user_id ,
      type:1,
      page:1
      }).then(res=>{
      res.momentList.forEach((item) => {
        item.topicName = item?.topicName?.split(',')
        item.images=item.images?.split(',')
        item.date = dateDiff(+new Date(item.createDate))
        if (item.content.length > 65) {
          item.expand = true
        } 
      })
      this.setData({
        list: type=='spinner'?[...this.data.attentionData, ...res.momentList  ] : res.momentList  ,
        showLoading: res.length >= 10,
        followed:res.followed,
      })
    })
  },
  newMoments(type){
    CommunityModule.Moments({ 
      condition:1 ,
      count:10,
      id:+this.data.id,
      userId:wx.getStorageSync('userInfo').user_id ,
      type:2,
      page:1
      }).then(res=>{
        res.momentList.forEach((item) => {
          item.topicName = item?.topicName?.split(',')
          item.images=item.images?.split(',')
          item.date = dateDiff(+new Date(item.createDate))
          if (item.content.length > 65) {
            item.expand = true
          } 
        })
      this.setData({
        newlist: type=='spinner'?[...this.data.attentionData, ...res.momentList  ] : res.momentList  ,
        showLoading: res.length >= 10,
        newfollowed:res.followed,
      })
    })

  },
  /**
   * Lifecycle function--Called when page load
   */
  onLoad: function (options) {
    this.setData({
      id:options.id,
      name:options.name,
      attentionNumber:options.attentionNumber,
      dynamicNumber:options.dynamicNumber,
      attentionState:options.attentionState
    })
    this.Moments()
  },

  /**
   * Lifecycle function--Called when page is initially rendered
   */
  onReady: function () {},

  /**
   * Lifecycle function--Called when page show
   */
  onShow: function () {},

  /**
   * Lifecycle function--Called when page hide
   */
  onHide: function () {},

  /**
   * Lifecycle function--Called when page unload
   */
  onUnload: function () {},

  /**
   * Page event handler function--Called when user drop down
   */
  onPullDownRefresh: function () {},

  /**
   * Called when page reach bottom
   */
  onReachBottom: function () {},

  /**
   * Called when user click on the top right corner to share
   */
  onShareAppMessage: function () {}
})
